package common;

import java.util.ArrayList;

import org.json.JSONObject;

import android.os.Parcel;
import android.os.Parcelable;

import Server.Post;

public class Promotion implements Parcelable{
	 private int id;
	    private String name;
	    private int store_id;
	    private String old_price;
	    private String descrese_price;
	    private String percent;
	    private int from_date;
	    private int to_date;
	    private int quantity;
	    private String description;
	    private ArrayList<PromotionImage> promotionImage;
	    private String image;
	    private String store_info; 
	    private Store store;
	    
	    public Promotion(int id, String name, int store_id, String old_price, String descrese_price, String percent, int from_date, int to_date, int quantity, String description) {
	        this.id = id;
	        this.name = name;
	        this.store_id = store_id;
	        this.old_price = old_price;
	        this.descrese_price = descrese_price;
	        this.percent = percent;
	        this.from_date = from_date;
	        this.to_date = to_date;
	        this.quantity = quantity;
	        this.description = description;
	    }
	    
	    public Promotion(int id, String name, int store_id, String old_price, String descrese_price, String percent, int from_date, int to_date, int quantity, String description,ArrayList<PromotionImage> lst)  {
	        this.id = id;
	        this.name = name;
	        this.store_id = store_id;
	        this.old_price = old_price;
	        this.descrese_price = descrese_price;
	        this.percent = percent;
	        this.from_date = from_date;
	        this.to_date = to_date;
	        this.quantity = quantity;
	        this.description = description;
	        this.promotionImage = lst;
	    }
	    
	    public Promotion(int id, String name, int store_id, String old_price, String descrese_price, String percent, int from_date, int to_date, int quantity, String description,ArrayList<PromotionImage> lst,String image)  {
	        this.id = id;
	        this.name = name;
	        this.store_id = store_id;
	        this.old_price = old_price;
	        this.descrese_price = descrese_price;
	        this.percent = percent;
	        this.from_date = from_date;
	        this.to_date = to_date;
	        this.quantity = quantity;
	        this.description = description;
	        this.promotionImage = lst;
	        this.image = image;
	    }
	    
	    public Promotion(int id, String name, int store_id, String old_price, String descrese_price, String percent, int from_date, int to_date, int quantity, String description,String image)  {
	        this.id = id;
	        this.name = name;
	        this.store_id = store_id;
	        this.old_price = old_price;
	        this.descrese_price = descrese_price;
	        this.percent = percent;
	        this.from_date = from_date;
	        this.to_date = to_date;
	        this.quantity = quantity;
	        this.description = description;
	        this.image = image;
	    }
	    public Promotion(int id, String name, int store_id, String old_price, String descrese_price, String percent, int from_date, int to_date, int quantity, String description,String image,String store_info)  {
	        this.id = id;
	        this.name = name;
	        this.store_id = store_id;
	        this.old_price = old_price;
	        this.descrese_price = descrese_price;
	        this.percent = percent;
	        this.from_date = from_date;
	        this.to_date = to_date;
	        this.quantity = quantity;
	        this.description = description;
	        this.image = image;
	        this.store_info = store_info;
	    }

	    public int getId() {
	        return id;
	    }

	    public String getName() {
	        return name;
	    }

	    public int getStore_id() {
	        return store_id;
	    }

	    public String getOld_price() {
	        return old_price;
	    }

	    public String getDescrese_price() {
	        return descrese_price;
	    }

	    public String getPercent() {
	        return percent;
	    }

	    public int getFrom_date() {
	        return from_date;
	    }

	    public int getTo_date() {
	        return to_date;
	    }

	    public int getQuantity() {
	        return quantity;
	    }

	    public String getDescription() {
	        return description;
	    }
	    
	    public ArrayList<PromotionImage>  getPromotionImage() {
	        return this.promotionImage;
	    }
	    
	    public String getImage() {
	        return image;
	    }
	    
	    public String getStoreInfo() {
	        return store_info;
	    }
	    public Store getStore() {
	        return store;
	    }
	    
	    public void setId(int id) {
	        this.id = id;
	    }

	    public void setName(String name) {
	        this.name = name;
	    }

	    public void setStore_id(int store_id) {
	        this.store_id = store_id;
	    }

	    public void setOld_price(String old_price) {
	        this.old_price = old_price;
	    }

	    public void setDescrese_price(String descrese_price) {
	        this.descrese_price = descrese_price;
	    }

	    public void setPercent(String percent) {
	        this.percent = percent;
	    }

	    public void setFrom_date(int from_date) {
	        this.from_date = from_date;
	    }

	    public void setTo_date(int to_date) {
	        this.to_date = to_date;
	    }

	    public void setStore(Store s) {
	        this.store = s;
	    }
	    public void setStoreInfo(String storeInfo) {
	        this.store_info = storeInfo;
	    }
	    
	    public void setQuantity(int quantity) {
	        this.quantity = quantity;
	    }

	    public void setDescription(String description) {
	        this.description = description;
	    }
	    
	    public void setPromotionImage(ArrayList<PromotionImage> lst) {
	        this.promotionImage = lst;
	    }
	    
	    public void setImage(String image) {
	        this.image = image;
	    }
	    
	    public static String getStringImagePromotion(ArrayList<PromotionImage> lst){
	    	String ch = config.config.char_split_image_promotion;
	    	String result = "";
	    	for(int i = 0 ; i < lst.size() ; i++){
	    		if(result.equals("")){
	    			result += lst.get(i).getUrl();
	    		}else{
	    			result += ch+lst.get(i).getUrl();
	    		}
	    	}	    	
	    	return result;
	    		    	
	    }	
	    
	    public static ArrayList<PromotionImage> SetStringImagePromotion(String str){
	    	String ch = config.config.char_split_image_promotion;
	    	ArrayList<PromotionImage> lst = new ArrayList<PromotionImage>();
	    	String arr[] = str.split(ch);
	    	
	    	for(int i = 0 ; i < arr.length ; i++){
	    		PromotionImage p = new PromotionImage(i, arr[i], 1);
	    		lst.add(p);	    		
	    	}	    	
	    	return lst;
	    		    	
	    }	
	    
	    public void  SetListImagePromotion(String str){
	    	String ch = config.config.char_split_image_promotion;
	    	ArrayList<PromotionImage> lst = new ArrayList<PromotionImage>();
	    	String arr[] = str.split(ch);
	    	
	    	for(int i = 0 ; i < arr.length ; i++){
	    		PromotionImage p = new PromotionImage(i, arr[i], 1);
	    		lst.add(p);	    		
	    	}	    	
	    	this.promotionImage = lst;
	    		    	
	    }	    
	    public void  SetStoreByString(String str){	     	
	    	JSONObject json = Post.ParseString2JsonObject(str); 
	    	ArrayList<Store> storeList = Post.parseJSONStore(json);
	    	Store s = storeList.get(0); 
	    	this.store= s; 
	    }

		@Override
		public int describeContents() {
			// TODO Auto-generated method stub
			return 0;
		}

		@Override
		public void writeToParcel(Parcel dest, int flags) {
			// TODO Auto-generated method stub
			
		}	
	    
}
